//
//  CourseCenterMenuCell.m
//  ShowYork
//
//  Created by hxh on 2020/8/30.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "LessonCenterMenuCell.h"

@interface LessonCenterMenuCell ()
@property (nonatomic,strong)UIView *coverView;
@property (nonatomic,strong)UIButton *menuBtn;
@property (nonatomic,assign)BOOL status;
@property (nonatomic,strong)NSIndexPath *indexPath;
@end

@implementation LessonCenterMenuCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.coverView = [[UIView alloc]init];
    self.coverView.layer.cornerRadius = 2.5;
    self.coverView.backgroundColor = RGBA(42, 119, 73, 1);
    [self.contentView addSubview:self.coverView];
    
    [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(5, 25));
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(15);
    }];
    
    self.menuBtn = [[UIButton alloc]init];
    [self.menuBtn setTitleColor:RGBA(51, 51, 51, 1) forState:UIControlStateNormal];
    self.menuBtn.titleLabel.font = font(14);
    [self.menuBtn addTarget:self action:@selector(clickMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.menuBtn];
    
    [self.menuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self);
    }];
}

- (void)clickMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(menuAtIndexPath:)]) {
        [self.delegate menuAtIndexPath:self.indexPath];
    }
}

- (void)updateCenterContent:(NSString *)content selectStatus:(BOOL)status indexPath:(NSIndexPath *)indexPath{
    self.status = status;
    self.indexPath = indexPath;
    self.menuBtn.backgroundColor = status?RGBA(242, 242, 242, 1):[UIColor whiteColor];
    [self.menuBtn setTitle:content forState:UIControlStateNormal];
    
}
+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"LessonCenterMenuCell";
    LessonCenterMenuCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[LessonCenterMenuCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}


@end
